/*
 * customer.cpp
 *
 *  Created on: Feb 22, 2016
 *      Author: ezhaome
 */
#include "customer.h"
#include "tools.h"
Customer::Customer(string name)
{
	_name = name;
}

void Customer::addRental(Rental rental)
{
	_rentals.push_back(rental);
}

string Customer::getName()
{
	return _name;
}

string Customer::statement()
{
	double totalAmount = 0;
	int frequentRenderPoints = 0;
	string result = "Rental record for " + getName() + "\n";
	vector<Rental>::iterator i = _rentals.begin();
	for (i = _rentals.begin(); i != _rentals.end(); i++)
	{
		double thisAmount = 0;
		switch(i->getMovie().getPriceCode())
		{
		case Movie::REGULAR:
			thisAmount += 2;
			if(i->getDaysRented() > 2)
			{
				thisAmount += (i->getDaysRented() - 2) * 1.5;
			}
			break;
		case Movie::NEW_RELEASE:
			thisAmount += i->getDaysRented() * 3;
			break;
		case Movie::CHILDREN:
			thisAmount += 1.5;
			if (i->getDaysRented() > 3)
			{
				thisAmount += (i->getDaysRented() - 3) * 1.5;
			}
			break;

		}

		frequentRenderPoints ++;
		if(i->getMovie().getPriceCode() == Movie::NEW_RELEASE &&
				i->getDaysRented() > 1)
		{
			frequentRenderPoints ++;
		}

		result += "\t" + i->getMovie().getTitle() + "\t" + intToString(thisAmount) + "\n";
		totalAmount += thisAmount;
	}

	result += "Amount owned is " + intToString(totalAmount) + "\n";
	result += "You earned " + intToString(frequentRenderPoints) + " frequent renter points";
	return result;
}
